package message.types.stringstring;

import java.io.IOException;

import message.Message;
import network.e2e.FrameReader;
import network.e2e.FrameWriter;
import stalker.Stalker;

public abstract class StringStringMessage extends Message {
  
  private String str1_, str2_;
  
  /**
   * Constructs a create a message that contains two strings
   * @requires parameters not null
   * @param client      The answerer
   * @param destination The recipient
   * @param str1        Content of first string
   * @param str2        Content of second string
   */
  
  public StringStringMessage(Stalker client, Stalker destination, String str1, String str2) {
    super(client, destination);
    assert str1 != null && str2 != null;
    str1_ = str1;
    str2_ = str2;
  }
  
  public StringStringMessage(Stalker client, Stalker destination, FrameReader reader) throws IOException {
    super(client, destination);
    str1_ = reader.readString();
    str2_ = reader.readString();
    assert str1_ != null && str2_ != null;
  }
  
  public String getFirstString() {
    return str1_;
  }
  
  public String getSecondString() {
    return str2_;
  }

  public boolean contentEquals(Object obj) {
    if (!(obj instanceof StringStringMessage)) {
      return false;
    }
    StringStringMessage that = (StringStringMessage) obj;
    return this.getClient().equals(that.getClient()) &&
           this.getDestination().equals(that.getDestination()) &&
           this.getFirstString().equals(that.getFirstString()) &&
           this.getSecondString().equals(that.getSecondString());
  }

  @Override
  public void send(FrameWriter writer) throws IOException {
    writer.writeString(str1_);
    writer.writeString(str2_);
  }
  
}
